# 构建阶段
FROM golang:1.24.1 AS builder

ENV GOPROXY=https://goproxy.cn,direct

WORKDIR /app

# 构建上下文根目录为 project-root，复制所有内容（包含 api、pkg、app/...）
COPY . ./

# 设置构建工作目录为 transfer-service
WORKDIR /app/app/transfer-service

# 编译
RUN go mod tidy && \
    mkdir -p bin/ && \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o ./bin/server ./cmd/server

# 运行阶段
FROM alpine:latest

RUN apk --no-cache add ca-certificates tzdata

ENV TZ=Asia/Shanghai

WORKDIR /app

# 拷贝可执行文件和配置
COPY --from=builder /app/app/transfer-service/bin/server /app/server
COPY --from=builder /app/app/transfer-service/configs /app/configs

EXPOSE 9641 9642
CMD ["./server", "-conf", "/app/configs/config.yaml"]
